package com.ajx.blog.service.impl;


import com.ajx.blog.entity.Blogusers;
import com.ajx.blog.service.api.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Mr.Li
 * @date: 2022/4/12 15:22
 * @description:
 */
@Component
public class UserDetailServiceImpl implements UserDetailsService {
    @Reference(url = "dubbo://localhost:20881" ,timeout = 2000)
     private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        System.out.println("###"+s);
             Blogusers blogusers =    userService.userLogin(s);
        System.out.println("*********************");
        List<SimpleGrantedAuthority> simpleGrantedAuthorities = new ArrayList<>();
            return new User(blogusers.getUname(), blogusers.getUpass(),simpleGrantedAuthorities );
    }
}
